package com.luck.easyfoodbatch.adapter;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.luck.easyfoodbatch.R;
import com.luck.easyfoodbatch.mvp.model.Batches;

import java.util.ArrayList;
import java.util.List;

/**
 * author：luck
 * project：EasyFoodBatch
 * package：com.luck.easyfoodbatch.adapter
 * email：893855882@qq.com
 * data：16/9/29
 */
public class BatchItemAdapter extends RecyclerView.Adapter<BatchItemAdapter.ItemViewHolder> {
    private int index = 0;
    private List<Batches.DataBean> list = new ArrayList<>();
    private Context mContext;

    public BatchItemAdapter(Context mContext, int index, List<Batches.DataBean> list) {
        super();
        this.index = index;
        this.list = list;
        this.mContext = mContext;
    }


    @Override
    public BatchItemAdapter.ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View rootView = LayoutInflater.from(parent.getContext()).inflate(R.layout.batch_list_item, parent, false);
        return new ItemViewHolder(rootView);
    }


    @TargetApi(Build.VERSION_CODES.M)
    @Override
    public void onBindViewHolder(final BatchItemAdapter.ItemViewHolder holder, final int position) {
        final Batches.DataBean bean = list.get(position);
        holder.ll_area.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
        holder.rl_price.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
        String province = bean.getSold_province();// 城市id
        String price = bean.getPrice();
        String province_zh = bean.getSold_province_zh();
        String single_price = bean.getSingle_price();
        String unit = bean.getUnit();
        holder.tv_price.setText(price);
        holder.tv_area.setText(province_zh);
        holder.tv_unit_price.setText(single_price);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ItemViewHolder extends RecyclerView.ViewHolder {
        TextView tv_area, tv_price, tv_unit_price;
        RelativeLayout rl_price;
        LinearLayout ll_area;

        public ItemViewHolder(View view) {
            super(view);
            tv_price = (TextView) view.findViewById(R.id.tv_price);
            tv_area = (TextView) view.findViewById(R.id.tv_area);
            rl_price = (RelativeLayout) view.findViewById(R.id.rl_price);
            ll_area = (LinearLayout) view.findViewById(R.id.ll_area);
            tv_unit_price = (TextView) view.findViewById(R.id.tv_unit_price);
        }
    }

}
